const enums = require('../enums')

class Response {
  constructor(code, message, data) {
    this.code = code
    this.data = data
    this.message = message
    this.success = code === enums.SUCCESS
  }
  Success(ctx) {
    ctx.body = new Response(enums.SUCCESS, '操作成功', null)
  }
  SuccssWithData(ctx, data) {
    ctx.body = new Response(enums.SUCCESS, '操作成功', data)
  }
  SuccessWithAll(ctx, msg, data) {
    ctx.body = new Response(enums.SUCCESS, msg, data)
  }
  Fail(ctx, msg) {
    ctx.body = new Response(enums.FAIL, msg, null)
  }
  FailWithCode(ctx, code, msg) {
    ctx.body = new Response(code, msg, null)
  }
}

module.exports = new Response()
